package com.lkd.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lkd.base.ResponseResult;
import com.lkd.domain.Node;
import com.lkd.pageParam.RegionDetailsPageParam;
import com.lkd.pageParam.RegionPageParam;
import com.lkd.service.INodeService;
import com.lkd.service.IRegionService;
import com.lkd.vo.NodeDetailsVo;
import com.lkd.vo.RegionDetailsVo;
import com.lkd.vo.RegionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.lkd.base.ResponseResult.success;

/**
 * <p>
 * 点位表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-02-10
 */
@RestController
@Api("点位相关接口")
@RequestMapping("/api/vm-service/node")
public class NodeController {
    @Autowired
    private INodeService nodeService;
    @ApiOperation("查看区域详情")
    @GetMapping("/search")
    public ResponseResult<Page<RegionDetailsVo>> getRegionDetailsVoPage(RegionDetailsPageParam param){
        Page<RegionDetailsVo> page =  nodeService.getRegionDetailsVoPage(param);
        return success(page);
    }
    @ApiOperation("新增点位")
    @PostMapping
    public ResponseResult add(Node node){
        nodeService.save(node);
        return success();
    }
    @ApiOperation("获取点位详情")
    @GetMapping("/vmList/{nodeId}")
    public ResponseResult<List<NodeDetailsVo>> getVmlistOfOneNode(@PathVariable Long nodeId){
        List<NodeDetailsVo> list = nodeService.getVmlistOfOneNode(nodeId);
        return success(list);
    }
    @ApiOperation("修改点位")
    @PutMapping("/{nodeId}")
    public ResponseResult updateNode(@PathVariable Long nodeId,@RequestBody Node node){
        nodeService.updateById(node);
        return success();
    }
    @ApiOperation("删除点位")
    @DeleteMapping("/{nodeId}")
    public ResponseResult deleteNode(@PathVariable Long nodeId){
        nodeService.removeById(nodeId);
        return success();
    }

}
